﻿@using System.Globalization
@using LERP.Domain.Enums
@using LERP.Web.App_Start
@using Sharp.Framework
@using Sharp.Framework.Extensions

@model MvcContrib.Pagination.IPagination<LERP.Web.Controllers.ViewModels.ReturnOrderViewModels.ReturnOrderListViewModel>
@{
    ViewBag.Title = "我的退单";
    Layout = "~/Views/Shared/_Layout.cshtml";
    var userRole = (UserRole)ViewBag.UserRole;
    var isAdmin = userRole != UserRole.User;
}
 
         @using (Html.BeginForm("Index", "ReturnOrder", FormMethod.Get))
         { 
             <table class="table_input"  style="width: 100%;">
                 <tr>
                     @if (isAdmin)
                     {
                           <th style="width: 50px;">员工:</th>
                     <td style="width:100px;">   
                        @Html.DropDownList("userId", (ViewBag.Users as List<SelectListItem>).InsertEmpty(), new { @class = "text-medium", style = "width: 99%;" })
                      </td> 
                     }
                      
                     <th style="width: 80px;">订单状态:</th>
                     <td style="width: 100px;">   
                          @Html.DropDownList("status", (ReturnOrderStatus.Close.ToDictionary().Select(m => new SelectListItem { Text = m.Key, Value = m.Value.ToString(CultureInfo.InvariantCulture) }).ToList()).InsertEmpty(), new { @class = "text-medium", style = "width: 99%;" })
                    </td>         <th style="width: 80px;">关键字:</th>
                     <td style="width: 100px;">
                           @Html.TextBox("keyword", "", new { @class = "text-medium", style = "width: 80%;" })
                     </td>
                     <td><input type="submit" class="button-submit" value="查询" />
                            @Html.ActionLinkEx("新建", "Create","ReturnOrder", new { returnUrl = Request.RawUrl }, new { }) 
                          @Html.ActionLinkEx("退单统计","Count", "ReturnOrder",new {  returnUrl = Request.RawUrl}, new { })
                     </td>
                 </tr>
                 

            </table>
             
         } 
@if (Model != null && Model.Any())
{
    <table class="table_list"  style="width: 99%;">
        <tr>
            <th style="width: 80px;">退单编码</th>
            <th>客户</th>
            <th style="width: 80px;">金额</th>
            <th style="width: 50px;">状态</th>
            <th style="width: 100px;">退单日期</th> 
            <th style="width: 100px;">操作</th>
        </tr>
        @foreach (var item in Model)
        {
            <tr><td> @Html.ActionLinkEx(item.Id.ToString(CultureInfo.InvariantCulture), "Details", "ReturnOrder", new {id = item.Id, returnUrl = Request.RawUrl}, new {@class = ""})</td>
                <td>@item.Customer</td>
                <td>@item.Amount</td>
                <td>@item.Status.GetDescription()</td>
                <td>@item.ReturnDate.ToString("yyyy年MM月dd日")</td>  
                <td  class="action">  
                    @switch (item.Status)
                    {
                        case ReturnOrderStatus.Draft:
                            {
                                @Html.ActionLinkEx("修改", "Edit", "ReturnOrder", new {id = item.Id, returnUrl = Request.RawUrl}, new {@class = ""})
                                @Html.ActionLinkEx("提交", "Apply", "ReturnOrder", new {id = item.Id, returnUrl = Request.RawUrl}, new {@class = ""})
                                @Html.ActionLinkEx("删除", "Delete", "ReturnOrder", new {id = item.Id, returnUrl = Request.RawUrl}, new {@class = "delete"})
                                break;
                            }
                        case ReturnOrderStatus.Cancel:
                            {
                                @Html.ActionLinkEx("删除", "Delete", "ReturnOrder", new {id = item.Id, returnUrl = Request.RawUrl}, new {@class = "delete"})
                                break;
                            }
                        case ReturnOrderStatus.Receipted:
                            {
                                @Html.ActionLinkEx("关闭", "Close", "ReturnOrder", new {id = item.Id, returnUrl = Request.RawUrl}, new {@class = "delete"})
                                break;
                            }
                        case ReturnOrderStatus.Recount:
                            {
                                @Html.ActionLinkEx("关闭", "Close", "ReturnOrder", new {id = item.Id, returnUrl = Request.RawUrl}, new {@class = "delete"})
                                break;
                            }
                        case ReturnOrderStatus.WaitForReceipt:
                            {
                                @Html.ActionLinkEx("修改", "Edit", "ReturnOrder", new {id = item.Id, returnUrl = Request.RawUrl}, new {@class = ""})
                                @Html.ActionLinkEx("回单", "Receipted", "ReturnOrder", new {id = item.Id, returnUrl = Request.RawUrl}, new {@class = ""})
                                break;
                            }
                    }
                </td>
            </tr>
        }             
    </table>

    <div class="page">
        @Html.Pager("page", Model.PageSize, Model.TotalItems)
    </div>
}
else
{
    <div class="empty">
        查询信息为空</div>
} 
@section Scripts {
    <script type="text/javascript">

        $(function () {
            $("a.delete").click(function () {
                return window.confirm("您确认要"+$(this).html()+"当前订单么?");

            });

        })

    </script>

}
